Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
The has-flag npm package is a simple utility that checks if a specific flag is provided in the command line arguments (process.argv). It is commonly used to determine if a flag is set when running a Node.js script from the terminal.
Check for the presence of a command line flag
This feature allows you to check if a flag, such as '--unicorn', is passed to the script. The code sample demonstrates how to use has-flag to check for the 'unicorn' flag and log a message if it is present.
const hasFlag = require('has-flag');
if (hasFlag('unicorn')) {
console.log('We have a unicorn!');
}
Minimist is a more comprehensive command line argument parsing library. Unlike has-flag, which only checks for the existence of flags, minimist parses all arguments into a structured object, making it easier to work with multiple types of command line parameters.
Commander is a complete solution for building command line applications in Node.js. It provides a high-level API for parsing command line options, as well as a variety of other features such as subcommands and automated help generation. Commander is more feature-rich compared to has-flag, which is focused solely on flag detection.
Yargs is another full-featured command line option parser that offers advanced features like command chaining, argument validation, and automatic help generation. It is more complex and feature-complete than has-flag, which is a minimalistic tool for flag checking.
Check if
argv
has a specific flag
Correctly stops looking after an --
argument terminator.
$ npm install has-flag
// foo.js
const hasFlag = require('has-flag');
hasFlag('unicorn');
//=> true
hasFlag('--unicorn');
//=> true
hasFlag('f');
//=> true
hasFlag('-f');
//=> true
hasFlag('foo=bar');
//=> true
hasFlag('foo');
//=> false
hasFlag('rainbow');
//=> false
$ node foo.js -f --unicorn --foo=bar -- --rainbow
Returns a boolean for whether the flag exists.
Type: string
CLI flag to look for. The --
prefix is optional.
Type: string[]
Default: process.argv
CLI arguments.
To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.
MIT © Sindre Sorhus
FAQs
Check if argv has a specific flag
The npm package has-flag receives a total of 197,888,850 weekly downloads. As such, has-flag popularity was classified as popular.
We found that has-flag demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.